﻿using System;
using System.ComponentModel;
using VNet.VisiSuite.Common.Resource;

namespace VNet.VisiSuite.VisiAdmin.Models
{
    public class AreaShiftModel : ComparableBaseModel<AreaShiftModel>, IDataErrorInfo
    {
        private int _areaShiftId;


        public int AreaShiftId
        {
            get { return _areaShiftId; }
            set
            {
                _areaShiftId = value;
                OnPropertyChanged("AreaShiftId");
            }
        }

        private int _areaId;
        public int AreaId
        {
            get { return _areaId; }
            set
            {
                _areaId = value;
                OnPropertyChanged("AreaId");
            }
        }

        private string _description;
        [Category("Properties")]
        [DisplayName("Description")]
        [Description("Area Shift Description.")]
        [DefaultValue("")]
        public string Description
        {
            get { return _description; }
            set
            {
                _description = value;
                OnPropertyChanged("Description", true);
            }
        }

        private DateTime? _startTime;
        [Category("Properties")]
        [DisplayName("Start Time")]
        [Description("Area Shift Start Time.")]
        public DateTime? StartTime
        {
            get { return _startTime; }
            set
            {
                _startTime = value;
                OnPropertyChanged("StartTime", true);
                OnPropertyChanged("StartTimeString");
            }
        }

        private DateTime? _endTime;
        [Category("Properties")]
        [DisplayName("End Time")]
        [Description("Area Shift End Time.")]
        public DateTime? EndTime
        {
            get { return _endTime; }
            set
            {
                _endTime = value;
                OnPropertyChanged("EndTime", true);
                OnPropertyChanged("EndTimeString");
            }
        }

        private bool _enabled;
        [Category("Properties")]
        [DisplayName("Enabled")]
        [Description("Enable / disable the Area Shift.")]
        public bool Enabled
        {
            get { return _enabled; }
            set
            {
                _enabled = value;
                OnPropertyChanged("Enabled", true);
            }
        }

        private bool _hidden;
        [Category("Properties")]
        [DisplayName("Hide")]
        [Description("Hide the Area Shift.")]
        public bool Hidden
        {
            get { return _hidden; }
            set
            {
                _hidden = value;
                OnPropertyChanged("Hidden", true);
            }
        }


        public string StartTimeString
        {
            get { return _startTime != null ? _startTime.Value.ToShortTimeString() : string.Empty; ; }
        }

        public string EndTimeString
        {
            get { return _endTime != null ? _endTime.Value.ToShortTimeString() : string.Empty; }
        }

        

        private string _createdBy;
        [Category("Update History")]
        [DisplayName("Created By")]
        [Description("User who created the area shift in VisiAdmin.")]
        public string CreatedBy
        {
            get { return _createdBy; }
            set
            {
                _createdBy = value;
                OnPropertyChanged("CreatedBy");
            }
        }

        private string _createdDate;
        [Category("Update History")]
        [DisplayName("Created On")]
        [Description("Date when the area shift was created in VisiAdmin.")]
        public string CreatedDate
        {
            get { return _createdDate; }
            set
            {
                _createdDate = value;
                OnPropertyChanged("CreatedDate");
            }
        }

        private string _lastUpdatedBy;
        [Category("Update History")]
        [DisplayName("Updated By")]
        [Description("User who last edited the area shift in VisiAdmin.")]
        public string LastUpdatedBy
        {
            get { return _lastUpdatedBy; }
            set
            {
                _lastUpdatedBy = value;
                OnPropertyChanged("LastUpdatedBy");
            }
        }

        

        private string _lastUpdatedDate;
        [Category("Update History")]
        [DisplayName("Updated On")]
        [Description("Date when the area shift was last edited in VisiAdmin.")]
        public string LastUpdatedDate
        {
            get { return _lastUpdatedDate; }
            set
            {
                _lastUpdatedDate = value;
                OnPropertyChanged("LastUpdatedDate");
            }
        }

        #region IDataErrorInfo Implementation

        public string Error
        {
            get { return string.Empty; }
        }

        public string this[string columnName]
        {
            get
            {
                if (!ShouldValidate)
                    return string.Empty;

                if (columnName == "Description" && string.IsNullOrWhiteSpace(Description))
                    return ValidationMessages.DescriptionRequired;
                else if (columnName == "StartTime" && StartTime == null)
                    return ValidationMessages.StartTimeRequired;
                else if (columnName == "EndTime" && EndTime == null)
                    return ValidationMessages.EndTimeRequired;
                return string.Empty; ;
            }
        }

        #endregion

        #region Override Equals methods
        public bool Equals(AreaShiftModel other)
        {
            if (ReferenceEquals(null, other))
                return false;
            if (ReferenceEquals(this, other))
                return true;

            return string.Equals(Description, other.Description)
                && TimeSpan.Equals(StartTime, other.StartTime)
                && TimeSpan.Equals(EndTime, other.EndTime)
                && Enabled == other.Enabled
                && Hidden == other.Hidden;
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj))
                return false;
            if (ReferenceEquals(this, obj))
                return true;
            if (obj.GetType() != this.GetType())
                return false;
            return Equals((AreaShiftModel)obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                var result = 0;
                result = (result * 397) ^ (Description ?? string.Empty).GetHashCode();
                result = (result * 397) ^ StartTime.GetHashCode();
                result = (result * 397) ^ EndTime.GetHashCode();
                result = (result * 397) ^ Enabled.GetHashCode();
                return result;
            }
        }
        #endregion
    }
}
